import React, { useState, useEffect } from 'react'
import RealApp from './views/app/App'
import Login from './views/login/Login'
import socket from './utils/io'
import { Idata } from './type/type'



export default function App() {
  const [isLogin, setIsLogin] = useState(false)
  const [data, setData] = useState<Idata[]>([])

  useEffect(() => {
    socket.on('sb register', (res: Idata[]) => {
      setData(res)
    })
    console.log(window.Notification.permission);
    if (window.Notification.permission == "denied") {
      window.Notification.requestPermission();
    }
  }, [])

  const toHome = () => {
    setIsLogin(true)
  }


  return (
    <div>
      {isLogin ? <RealApp onLiveList={data} /> : <Login toHome={toHome} />}
    </div>
  )
}
